package com.wolfcode.goods.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.goods.domain.info.GoodsInfo;
import com.wolfcode.goods.domain.vo.GoodsSaveVo;
import com.wolfcode.goods.domain.vo.GoodsUpdateVo;
import com.wolfcode.goods.domain.vo.GoodsVo;
import com.wolfcode.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 物品信息Controller
 *
 * @author wolfcode
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/goods/goods")

public class GoodsController extends BaseController {

    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询物品信息列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsVo goods) {
        startPage();
        List<GoodsInfo> list = goodsService.selectGoodsInfoList(goods);
        return getDataTable(list);
    }


    /**
     * 获取物品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(goodsService.selectGoodsById(id));
    }


    /**
     * 新增物品信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:add')")
    @Log(title = "物品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public void add( GoodsSaveVo goods) throws Exception {
        goodsService.insertGoods(goods);
    }

    /**
     * 修改物品信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:edit')")
    @Log(title = "物品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit( GoodsUpdateVo goods) throws Exception {
        goodsService.updateGoods(goods);
    }

    /**
     * 删除物品信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:remove')")
    @Log(title = "物品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(goodsService.deleteGoodsById(id));
    }
}
